package p200;

public class Leetcode_209 {
        public int minSubArrayLen(int s, int[] nums) {
            // 滑动窗口
            int min = Integer.MAX_VALUE;
            int right = 0, left = 0;
            int count = 0;
            while (right < nums.length) {
                count += nums[right];
                if (count >= s) {
                    while (count >= s) {
                        count -= nums[left++];
                    }
                    if (right - left + 2 < min) {
                        min = right - left + 2;
                    }
                }
                right++;
            }
            if (min == Integer.MAX_VALUE) {
                return 0;
            }
            return min;
    }
}
